<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <title>我要认证</title>
    <link rel="stylesheet" href="../css/ydui.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <script src="../js/ydui.flexible.js"></script>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
</head>

<body>
    <div class="iwantPage g-view" id="iwantPage">
        <div class="m-celltitle min-title bornone">认证类型</div>
        <div class="m-cell min-mb-none" id="setupPage">
            <label class="cell-item">
                <span class="cell-left">业务经理</span>
                <label class="cell-right">
                    <input :value="0" type="radio" name="radio" checked="true" />
                    <i class="cell-radio-icon"></i>
                </label>
            </label>
            <label class="cell-item bornone">
                <span class="cell-left">生产厂家</span>
                <label class="cell-right">
                    <input :value="1" type="radio" name="radio" />
                    <i class="cell-radio-icon"></i>
                </label>
            </label>
        </div>
        <div class="m-celltitle min-title">认证信息</div>
        <div class="m-cell min-mb-none">
            <div class="cell-item">
                <div class="cell-left">姓&nbsp;&nbsp;&nbsp;名：</div>
                <div class="cell-right">
                    <input :value="iwant_obj.truename" id="nameId" type="text" class="cell-input" placeholder="请输入您的姓名或公司名称" autocomplete="off"
                    />
                </div>
            </div>
            <div class="cell-item">
                <div class="cell-left">身份证：</div>
                <div class="cell-right">
                    <input :value="iwant_obj.auth_number" id="cardId" type="number" pattern="[0-9]*" class="cell-input" placeholder="请输入您的身份证号或营业执照"
                        autocomplete="off" />
                </div>
            </div>
        </div>
        <div class="m-celltitle min-title">上次身份证正反面或营业执照</div>
        <div class="upload">
            <div class="img_ul">
                <div class="img_li" :classid="item" v-for="(item, index) in img_arry" :key="index">
                    <img class="idcard" :src="paraurl+item" alt="">
                    <img @click="delect(index)" class="delect_img" src="../icon/delect.png" alt="" srcset="">
                </div>
            </div>
            <div class="imgupload" @click="uploads">
                <img src="../icon/tianjia.png" alt="" srcset="">
            </div>
        </div>
        <button @click="iwantSubmit" class="btn-block btn-primary">提交</button>
    </div>
    <footer class="m-tabbar tabbar-fixed">
        <a href="../index.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe617;</i>
            </span>
            <span class="tabbar-txt">询盘商机</span>
        </a>
        <a href="../setup.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:20px" class="icon iconfont">&#xe698;</i>
            </span>
            <span class="tabbar-txt">设置商机</span>
        </a>
        <a href="../release.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:22px" class="icon iconfont">&#xe662;</i>
            </span>
            <span class="tabbar-txt">发布商机</span>
        </a>
        <a href="../vip.html" class="tabbar-item tabbar-active">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe67e;</i>
            </span>
            <span class="tabbar-txt">会员中心</span>
        </a>
    </footer>
    <script src="../js/jquery-3.3.1.min.js"></script>
    <script src="../js/ydui.flexible.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../js/ydui.js"></script>
    <script src="../js/nuoxia.js"></script>
    <script>
        window.onload = function () {
            var token = window.localStorage.getItem("token")
            var iwantPage = new Vue({
                el: "#iwantPage",
                data: {
                    img_arry: [],
                    iwant_obj: {},
                    paraurl: "http://dingdan.hihaoge.me"
                },
                filters: {

                },
                mounted: function () {
                    this.iwantView();
                },
                methods: {
                    iwantView: function () {
                        var _this = this;
                        var checkbox_arry = [];
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/user/renzheng?tm=" + tm,
                            data: {
                                token: token
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.iwant_obj = data.data;
                                    _this.img_arry = (data.data.auth_image).split(",");
                                }
                            }
                        })
                    },
                    iwantSubmit: function () {
                        var names = $("#setupPage input[name='radio']");
                        var values = [];
                        for (var i = 0; i < names.length; i++) {
                            if (names[i].checked) {
                                values.push(names[i].value)
                            }
                        }
                        var auth_type = values.toString();
                        var truename = $("#nameId").val();
                        var auth_number = $("#cardId").val();
                        var auth_image = this.img_arry.toString();
                        $.ajax({
                            type: "post",
                            url: paraurl + "api/user/renzheng?token=" + token + "&tm=" + tm,
                            data: {
                                "auth_type": auth_type,
                                "truename": truename,
                                "auth_number": auth_number,
                                "auth_image": auth_image
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    YDUI.dialog.toast(data.msg, 'success', 2000, function () {
                                    });
                                } else {
                                    YDUI.dialog.alert(data.msg);
                                    
                                }
                            }
                        })
                    },
                    uploads: function () {
                        var _this = this;
                        var appId;
                        var timestamp;
                        var nonceStr;
                        var signature;
                        var urls = window.location.href;
                        $.ajax({//获取微信参数
                            type: "post",
                            url: paraurl + "/api/common/getWechatSignPackage?url=" + urls,
                            data: {
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    appId = data.data.appId;
                                    timestamp = data.data.timestamp;
                                    nonceStr = data.data.nonceStr;
                                    signature = data.data.signature;
                                    wx.config({
                                        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                                        appId: appId, // 必填，公众号的唯一标识
                                        timestamp: timestamp, // 必填，生成签名的时间戳
                                        nonceStr: nonceStr, // 必填，生成签名的随机串
                                        signature: signature,// 必填，签名
                                        jsApiList: ['chooseImage', 'previewImage', 'uploadImage', 'downloadImage'] // 必填，需要使用的JS接口列表
                                    });
                                    wx.ready(function () {
                                        wx.checkJsApi({
                                            jsApiList: ['chooseImage', 'previewImage', 'uploadImage', 'downloadImage'],
                                            success: function (res) {
                                                if (res.checkResult.getLocation == false) {
                                                    alert('你的微信版本太低，不支持微信JS接口，请升级到最新的微信版本！');
                                                    return;
                                                } else {
                                                    wx.chooseImage({
                                                        count: 1, // 默认9
                                                        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                                                        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
                                                        success: function (res) {
                                                            var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                                                            _this.uploadImage(localIds[0], 1)
                                                        }
                                                    });
                                                }
                                            }
                                        });
                                    });
                                    wx.error(function (res) {
                                        // config信息验证失败会执行error函数，如签名过期导致验证失败，具体错误信息可以打开config的debug模式查看，也可以在返回的res参数中查看，对于SPA可以在这里更新签名。
                                        alert(res);
                                    });
                                } else {
                                    return false;
                                }
                            },
                            error: function () {
                                return false;
                            }
                        })
                    },
                    uploadImage: function (localIds, index) {
                        var _this = this;
                        wx.uploadImage({
                            localId: localIds, // 需要上传的图片的本地ID，由chooseImage接口获得
                            isShowProgressTips: 1, // 默认为1，显示进度提示
                            success: function (res) {
                                var serverId = res.serverId; // 返回图片的服务器端ID
                                wx.downloadImage({
                                    serverId: serverId, // 需要下载的图片的服务器端ID，由uploadImage接口获得
                                    isShowProgressTips: 1, // 默认为1，显示进度提示
                                    success: function (res) {
                                        var localId = res.localId; // 返回图片下载后的本地ID
                                        wx.getLocalImgData({
                                            localId: localId, // 图片的localID
                                            success: function (res) {
                                                var localData = res.localData; // localData是图片的base64数据，可以用img标签显示
                                                _this.upload(index, localData)
                                            }
                                        });
                                    }
                                });
                            }
                        });
                    },
                    upload: function (id, e) {
                        var _this = this;
                        e = e.replace("image/jgp", "image/jpg");
                        $.ajax({
                            type: "post",
                            url: paraurl + "/api/common/base64imgsave",
                            data: {
                                "token": token,
                                "file": e
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    var img_arry=_this.img_arry.unshift(data.data);
                                } else {
                                    return false;
                                }
                            },
                            error: function (res) {
                                alert("错误" + res)
                                return false;
                            }
                        })
                    },
                    delect:function(index){
                        var img_arry=this.img_arry;
                        var s_arry=img_arry.splice(index,1)
                        _this.img_arry=img_arry;
                    }
                }
            })
        }
    </script>
</body>

</html>